<template>
  <div class="content-year">
    <div class="year-btn">
      <el-button size="small" class="m-r-20" type="primary" @click="commitBoard(3)">预 览</el-button>
      <el-button size="small" class="m-r-20" type="primary" @click="commitBoard(0)" plain>暂 存</el-button>
      <el-button size="small" type="primary" @click="commitBoard(1)">提 交</el-button>
    </div>
    <div class="year-con">
      <YearSummary
        ref="yearSum"
        :disabled="$route.query.isEnd == 'true' ? true : false"
        :info="formData"
        @subMit="submmitData" />
    </div>

    <XnDialog
      title="预览"
      :visible.sync="tabDialogShow"
      class="branch_dialog"
      @closed="tabDialogShow = false"
      top="5vh"
      width="1000px">
      <div class="dialog-con">
        <YearSummary :disabled="true" v-if="tabDialogShow" :info="formData" />
      </div>
    </XnDialog>
  </div>
</template>

<script>
import YearSummary from '../detail/YearSummary'
import XnDialog from '@com/xnDialog.vue'
import {} from '@apis/board.js'
import { cloneDeep } from 'lodash'
export default {
  name: 'WriteContentQuarter',
  components: { YearSummary, XnDialog },
  props: {
    info: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      // 路由传参
      routerQuery: {},
      formData: {},
      tabDialogShow: false,
      commitType: 0,
    }
  },
  watch: {
    info: {
      handler(news) {
        if (news.noteId) {
          this.formData = cloneDeep(news)
        }
      },
      deep: true,
    },
  },
  computed: {},
  created() {
    this.routerQuery = Object.assign({}, this.$route.query)
  },
  mounted() {
    if (this.info.noteId) {
      this.formData = cloneDeep(this.info)
    }
  },
  methods: {
    // 提交
    commitBoard(saveStatus) {
      this.commitType = saveStatus
      this.$refs.yearSum.addSum(saveStatus)
    },
    submmitData(data) {
      this.formData = data
      if (this.commitType === 0) {
        this.$message.success('暂存成功')
      } else if (this.commitType === 1) {
        this.$message.success('提交成功')
        this.$router.go(-1)
      } else if (this.commitType === 3) {
        console.log('123456 :>> ', 123456)
        this.tabDialogShow = true
      }
    },
  },
}
</script>
<style lang="scss" scoped>
.content-year {
  width: 100%;
  height: 100%;
  .year-btn {
    position: absolute;
    right: -380px;
    top: -60px;
  }
  .year-con {
    padding: 10px 20px;
    height: 100%;
    overflow-y: auto;
  }
}
.dialog-con {
  height: 70vh;
  overflow-y: auto;
}
</style>
